<?php

namespace app\common\model;

use app\model\Area;

/**
 * @property int $admin_id 管理员ID (执行端)
 * @property int $committees_id 村委会ID
 * @property int $id
 * @property int $street_id 片区ID
 * @property-read mixed $area_txt
 * @property-read mixed $committees_txt
 * @property-read mixed $street_txt
 */
class AdminStreet extends BaseModel
{
    // 表名
    protected $name = 'admin_street';
    protected $pk = 'id';


    // 自动写入时间戳字段
    //protected $autoWriteTimestamp = false;

    // 追加属性
    protected $append = [
        'street_txt',
        'committees_txt',
        'area_txt',
    ];

    public function getStreetTxtAttr($value, $data)
    {
        $area = Area::cache(true)
                    ->where('area_id', $data['street'])
                    ->find();
        return $area['area_name'];
    }

    public function getCommitteesTxtAttr($value, $data)
    {
        $area = Area::cache(true)
                    ->where('area_id', $data['committees'])
                    ->find();
        return $area['area_name'];
    }

    public function getAreaTxtAttr($value, $data)
    {
        $area = Area::cache(true)
                    ->where('area_id', $data['area'])
                    ->find();
        return $area['area_name'];
    }

}
